#!/bin/bash
#最好手动部署etcd，否则出错搞死人
#编辑主文件。
vi /usr/local/kubernetes/cfg/etcd
#[Member]
ETCD_NAME="etcd1"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.31.121:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.31.121:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.31.121:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.31.121:2379"
ETCD_INITIAL_CLUSTER="etcd1=https://192.168.31.121:2380,etcd2=https://192.168.31.126:2380,etcd3=https://192.168.31.128:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"


vi /lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=/usr/local/kubernetes/cfg/etcd
ExecStart=/usr/local/kubernetes/bin/etcd \
--name=${ETCD_NAME} \
--data-dir=${ETCD_DATA_DIR} \
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} \
--initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
--initial-cluster=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-token=${ETCD_INITIAL_CLUSTER_TOKEN} \
--initial-cluster-state=new \
--cert-file=/usr/local/kubernetes/ssl/etcd.pem \
--key-file=/usr/local/kubernetes/ssl/etcd-key.pem \
--peer-cert-file=/usr/local/kubernetes/ssl/etcd.pem \
--peer-key-file=/usr/local/kubernetes/ssl/etcd-key.pem \
--trusted-ca-file=/usr/local/kubernetes/ssl/ca.pem \
--peer-trusted-ca-file=/usr/local/kubernetes/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
